package com.eastfair.home.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.home.dto.ExhibitionDrawingDTO;
import com.eastfair.home.entity.ExhibitionDrawing;
import com.eastfair.home.dto.ExhibitionDrawingSaveDTO;
import com.eastfair.home.dto.ExhibitionDrawingUpdateDTO;
import com.eastfair.home.dto.ExhibitionDrawingPageQuery;
import com.eastfair.home.service.ExhibitionDrawingService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.home.vo.ExhibitionDrawingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 展会图纸分类
 * </p>
 *
 * @author dq
 * @date 2022-10-25
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionDrawing")
@Api(value = "ExhibitionDrawing", tags = "展会图纸分类")
@PreAuth(replace = "home:exhibitionDrawing:")
public class ExhibitionDrawingController extends SuperController<ExhibitionDrawingService, Long, ExhibitionDrawing, ExhibitionDrawingPageQuery, ExhibitionDrawingSaveDTO, ExhibitionDrawingUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ExhibitionDrawingService exhibitionDrawingService;

    @Override
    public void handlerResult(IPage<ExhibitionDrawing> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<ExhibitionDrawing> exhibitionDrawingList = list
                .stream()
                .map((map) -> ExhibitionDrawing.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(exhibitionDrawingList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionDrawingPageQuery> params) {
        ExhibitionDrawingPageQuery pageQuery = params.getModel();
    }

    /**
     * 主场ID批量保存展会图纸.
     *
     * @param list   the list
     * @param homeId the home id
     * @return the r
     */
    @ApiOperation("主场ID批量保存展会图纸")
    @PostMapping("/saveBatch")
    public R<Boolean> saveBatch(@RequestBody List<ExhibitionDrawingDTO> list, @RequestParam("homeId") Long homeId) {
        log.info("saveBatch - 主场ID批量保存展会图纸, homeId={}", homeId);
        return R.successDef(exhibitionDrawingService.saveBatch(list, homeId));
    }

    /**
     * 主场ID批量保存展会图纸.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("主场ID批量保存展会图纸")
    @PostMapping("/query/exhibition")
    public R<Page<ExhibitionDrawingVO>> queryExhibitionByDrawingId(@RequestBody PageParams<ExhibitionDrawingDTO> pageParams) {
        log.info("queryExhibitionByDrawingId - 分页查询展会图纸分类关系列表, pageParams={}", pageParams);
        return R.successDef(exhibitionDrawingService.listExhibitionByDrawingId(pageParams));
    }
}
